import axios from 'axios';

const instance = axios.create({
  baseURL: 'http://taishun.xyz:8000',
  withCredentials: true,
});

instance.interceptors.request.use(config => {
  const ck = JSON.parse(localStorage.getItem('ck') as string)
  let params = config.params
  if (ck) {
    params = { ...params, cookie: ck.cookie }
  } else {
    console.log('去登入')
  }
  return {
    ...config, params
  };
}, err => {

});

instance.interceptors.response.use(res => {
  return res;
}, err => {
  if (err && err.response) {
    switch (err.response.status) {
      case 400:
        console.log("请求错误");
        break;
      case 401:
        console.log("未授权访问");
        break;
      default:
        console.log("其他错误信息");
    }
  }
  return err;
});



export default instance;

